var isUpProductBuy = false;
var isDownProductBuy = false;
/*function toBuy(prodId, isBuy) {
    layer.confirm('确定要进行此操作吗?', function() {
        $.ajax({
            url : path + "/product/to_buy",
            cache : false,
            type : 'post',
            dataType : 'html',
            data : {
                "prodId" : prodId,
                "isBuy" : isBuy
            },
            error : function() {
                layer.alert("操作失败!");
            },
            success : function(data) {
                if (data.charAt(0) == '1') {
                    layer.alert("您的操作成功", function() {
                        $(checkboxs).val("");
                        $(upOrDown).val("");
                        $(query_product_form).submit();
                    });
                } else if (data.charAt(0) == '2') {
                    layer.alert("当前商品正参与秒杀，在秒杀结束后才允许上架");
                } else {
                    layer.alert("您的操作失败!请确定商品状态!");
                }
            }
        });    
    });    
}
*/
function search() {
    var orderNo = document.getElementsByName("orderNo")[0].value;
     
    var startDate = $('#startDate').val();
    var endDate = $('#endDate').val();
     
    if (orderNo != '' && isNaN(orderNo)) {
        layer.alert("输入的商品编号有误，请重新输入！");
        return;
    }
    if ((startDate.length != 0 && startDate != '')
            && (endDate.length != 0 && endDate != '')) {
        var startTime1 = startDate.slice(0, 4) + startDate.slice(5, 7)
                + startDate.slice(8, 10);
        var endTime1 = endDate.slice(0, 4) + endDate.slice(5, 7)
                + endDate.slice(8, 10);
        var timeValue1 = endTime1 - startTime1;
        if (timeValue1 < 0) {
            layer.alert("结束时间必须大于或等于开始时间!");
            return;
        }
    }
    // **** 功能 方法 *******
    initPage();
    layer.load(1);
    $(query_order_form).submit();
}
function searchs( oroderState){
    toIsEmpty();
    $("#state").val(oroderState);    
    search();
}
function refresh(){
	$(query_order_form).submit();
}
function toIsEmpty() {
    $("#startDate").val("");
    $("#endDate").val("");
    $("#state").val("");    
    $("#orderNo").val("");
    $("#prodType").val("");
    $("#xn_phone").val("");
    $("#recName").val("");
    $("#prodName").val("");
    $("#memberNo").val("");
    //$('#query_order')[0].reset();
}
 
function initPage() {
    document.getElementById("page").value = '1';
}
function trims(str) {
    return str.replace(/^\s+|\s+$/g, "");
}
 
function saveCheckBoxs() {
    var checkBoxList = $("input:checkbox[name='ProducIsBuyId']");
    var list = [];
    checkBoxList.each(function() { // 遍历name=test的多选框
        if ($(this).prop("checked") && !$(this).prop("disabled")) {// 如果选择且为可选
            var state = $(this).prop("checked");
            if (state) {
                var map = {};
                var id_value = $(this).attr("id");
                var id_text = $("#productBuy" + id_value).parent().text();
                map["id"] = id_value;
                map["isBuy"] = id_text.trim() == "已上架" ? "4" : "5";// isBuy;是否上架
                                                                    // ： 5.上架
                                                                    // 4.下架6.过期
                list.push(map);
            }
        }
    });
    var jsonStr = JSON.stringify(list);
    jsonStr = appendJSON(jsonStr);
    $(checkboxs).val(jsonStr);
    if (isUpProductBuy) {
        $(upOrDown).val("1");
    } else if (isDownProductBuy) {
        $(upOrDown).val("0");
    }
}
/*
function appendJSON(jsonStr) {
    if (jsonStr.length < 3) {
        return $(checkboxs).val();
    }
    if ($(checkboxs).val().length > 2) {
        jsonStr = $(checkboxs).val() + "," + jsonStr;
        jsonStr = jsonStr.replace(/\[/g, "");
        jsonStr = jsonStr.replace(/\]/g, "");
        jsonStr = "[" + jsonStr + "]";
    }
    return jsonStr;
}
 
function idIsInJSON(obj) {
    if ($(checkboxs).val().length < 1) {
        return;
    }
    ;
    var arr = eval($(checkboxs).val());
    for (var i = 0; i < arr.length; i++) {
        var newobj = arr[i];
        if (newobj.id == obj.id) {
            $(obj).prop("checked", "checked");
            arr.splice(i, 1);
            i--;
        }
    }
    var jsonStr = JSON.stringify(arr);
    $(checkboxs).val(jsonStr);
}
 
 
审核
 function audit_product(title,url,id,w,h){
            var index = layer.open({
                type: 2,
                title: title,
                content: url
            });
            layer.full(index);
        }
 
 查看
 function look_product(title,url,id,w,h){
            var index = layer.open({
                type: 2,
                title: title,
                content: url
            });
            layer.full(index);
        }
 
 
 编辑
 function edit_product(title,url,id,w,h){
            var index = layer.open({
                type: 2,
                title: title,
                content: url
            });
            layer.full(index);
        }
 
 
 function thisValueForState(obj){
     
     $("#cancleMileageInfoQo.state").val(obj);
 }*/
 
 
 
//------------审核订单-------------
function orderVerify(orderId){
    
     if(orderId.length>17){
            alert("订单号长度不能大于17位！");    
            return false;    
     }
     var index = layer.open({
       type: 2,
       title: '订单审核',
       scrollbar: false,
       content: path+"/tbOrder/order_verify?id="+orderId,
       area: ['550px', '400px']
   });
}
//----------订单编辑地址查看---------
 
function showOrderSendAddress(orderId){
    
     if(orderId.length>17){
            alert("订单号长度不能大于17位！");    
            return false;    
     }
     var index = layer.open({
      type: 2,
      title: '订单修改',
      scrollbar: false,
      content: path+"/tbOrder/order_detail_updaddress?id="+orderId,
      area: ['1080px', '650px']
  });
}
 
function showOrderDescMsg(orderId){
     if(orderId.length>17){
            alert("订单号长度不能大于17位！");    
            return false;    
     }
    var index = layer.open({
    type: 2,
    title: '订单备注',
    scrollbar: false,
    content: path+"/tbOrder/order_desc_msg?id="+orderId,
    area: ['550px', '400px']
});
}
 
function reSend(orderId){
    layer.confirm("确定操作？",function(){
        $.ajax({
            url : path+"/tbOrder/send_message",
            cache : false,
            type : 'post',
            dataType : "text",
            data : {
                "orderId" : orderId 
            },
            error : function() {
                layer.alert("操作失败!");
            /*    layer.msg('发送失败',{icon:w1,time:1000},function(){
 
                   });*/
            },
            success : function(data) {
                      
                      var resultArr = data.split(",");
                     if(resultArr[0] == "success"){
                       layer.msg('操作成功!',{icon:1,time:1000},function(){
                       });
                       /* window.location.href = path+"/user/TbOrderAction!queryTbOrderPage.action";*/
                        
                     }else{
                       layer.msg('发送失败',{icon:1,time:1000},function(){
 
                       });
                     }
                     
                 }
        });    
         
        
    });
 
    
}
 
 
function showOrderOperation(orderId){
     if(orderId.length>17){
            alert("订单号长度不能大于17位！");    
            return false;    
     }

    var index = layer.open({
    type: 2,
    title: '订单备注',
    scrollbar: false,
    content: path+"/tbOrder/order_detil_operation?id="+orderId,
    area: ['800px', '600px']
    });
}
